//
//  OnlineOLTotalTableViewCell.m
//  ShangHaiHuDongApp
//
//  Created by apple on 17/9/4.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "OnlineOLTotalTableViewCell.h"

@implementation OnlineOLTotalTableViewCell


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initMyCell];
    }
    return self;
}


-(void)initMyCell{
    [self.contentView addSubview:self.ybContentLabel];
    [self.contentView addSubview:self.openButton];
    [self.contentView addSubview:self.timeLabel];
    [self.contentView addSubview:self.bottomView];
    
    self.ybContentLabel.sd_layout.leftSpaceToView(self.contentView , ItemWidth * 24).topSpaceToView(self.contentView , ItemHeight * 31).widthIs(1).heightIs(1);
    
    self.openButton.sd_layout.leftSpaceToView(self.contentView , 0).topSpaceToView(self.ybContentLabel , ItemHeight * 10).widthIs(ItemWidth * 130).bottomSpaceToView(self.contentView , ItemHeight * 31);
    
    self.timeLabel.sd_layout.rightSpaceToView(self.contentView , ItemWidth * 24).topSpaceToView(self.ybContentLabel , ItemHeight * 20).widthIs([UIScreen zj_screenWith] / 2).bottomSpaceToView(self.contentView , ItemHeight * 41);
    
    self.bottomView.sd_layout.leftSpaceToView(self.contentView , 0).bottomSpaceToView(self.contentView , 0).rightSpaceToView(self.contentView , 0).heightIs(ItemHeight * 16);
    
}


-(void)setModel:(OnlineOLTotalModel *)model
{
    _model = model;
    if (model.isMoreThanFiveLine) {
        self.openButton.hidden = NO;
        if (model.isOpen) {
            self.ybContentLabel.sd_layout.leftSpaceToView(self.contentView , ItemWidth * 24).topSpaceToView(self.contentView , ItemHeight * 31).widthIs(model.onContentSize.width).heightIs(model.onContentSize.height);
            [self.ybContentLabel updateLayout];
            self.ybContentLabel.attributedText = model.onContentAttributedString;
        }
        else{
            self.ybContentLabel.sd_layout.leftSpaceToView(self.contentView , ItemWidth * 24).topSpaceToView(self.contentView , ItemHeight * 31).widthIs(model.offContentSize.width).heightIs(model.offContentSize.height + 8);
            [self.ybContentLabel updateLayout];
            self.ybContentLabel.attributedText = model.offContentAttributedString;
        }
    }
    else{
        self.openButton.hidden = YES;
        self.ybContentLabel.sd_layout.leftSpaceToView(self.contentView , ItemWidth * 24).topSpaceToView(self.contentView , ItemHeight * 31).widthIs(model.onContentSize.width).heightIs(model.onContentSize.height);
        [self.ybContentLabel updateLayout];
        self.ybContentLabel.attributedText = model.onContentAttributedString;
    }
    self.timeLabel.text = model.SUMMARY_LASTTIME;
}


-(void)option_openButton:(UIButton *)sender{
    sender.selected = !sender.selected;
    if (self.delegate && [self.delegate respondsToSelector:@selector(didClickOpenButtonWithBottonOpenState:)]) {
        [self.delegate didClickOpenButtonWithBottonOpenState:sender.selected];
    }
}

-(UILabel *)ybContentLabel
{
    if (!_ybContentLabel) {
        _ybContentLabel = [ToolClass creatLabelWithFrame:CGRectMake(1, 1, 1, 1) font:16 textColor:[UIColor textBlackColor] text:@""];
    }
    return _ybContentLabel;
}


-(UIButton *)openButton
{
    if (!_openButton) {
        _openButton = [ToolClass createButtonWithFrame:CGRectMake(1, 1, 1, 1) text:@"全文" textColor:[UIColor themeColor] imageName:@"" font:16];
        [_openButton setTitle:@"收起" forState:UIControlStateSelected];
        _openButton.selected = NO;
        _openButton.titleEdgeInsets = UIEdgeInsetsMake(0, ItemWidth * 24, 0, 0);
        [_openButton addTarget:self action:@selector(option_openButton:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _openButton;
}

-(UILabel *)timeLabel
{
    if (!_timeLabel) {
        _timeLabel = [ToolClass creatLabelWithFrame:CGRectMake(1, 1, 1, 1) font:14 textColor:[UIColor textLightGrayColor] text:@""];
        _timeLabel.textAlignment = NSTextAlignmentRight;
    }
    return _timeLabel;
}

-(UIView *)bottomView
{
    if (!_bottomView) {
        _bottomView = [[UIView alloc]initWithFrame:CGRectMake(1, 1, 1, 1)];
        _bottomView.backgroundColor = [UIColor themeGrayColor];
    }
    return _bottomView;
}

@end
